home *** CD-ROM | disk | FTP | other *** search
- /* User subroutines for AX.25 */
- #include "global.h"
- #include "mbuf.h"
- #include "timer.h"
- #include "iface.h"
- #include "lapb.h"
- #include "ax25.h"
- #include "lapb.h"
- #include <ctype.h>
-
- extern int32 Axirtt;
- struct ax25_cb *cr_ax25();
- void lapbstate(),recover();
-
- /* Open an AX.25 connection */
- struct ax25_cb *
- open_ax25(iface,local,remote,window,r_upcall,t_upcall,s_upcall,user)
- struct iface *iface; /* Interface */
- struct ax25_addr *local; /* Local address */
- struct ax25_addr *remote; /* Remote address */
- int16 window; /* Window size in bytes */
- void (*r_upcall)(); /* Receiver upcall handler */
- void (*t_upcall)(); /* Transmitter upcall handler */
- void (*s_upcall)(); /* State-change upcall handler */
- int user; /* User linkage area */
- {
- struct ax25_cb *axp;
-
- if((axp = find_ax25(remote)) != NULLAX25 && axp->state != DISCONNECTED)
- return NULLAX25; /* Only one to a customer */
-
- if(axp == NULLAX25 && (axp = cr_ax25(remote)) == NULLAX25)
- return NULLAX25;
- ASSIGN(axp->remote,*remote);
- ASSIGN(axp->local,*local);
- axp->iface = iface;
- axp->window = window;
- axp->r_upcall = r_upcall;
- axp->t_upcall = t_upcall;
- axp->s_upcall = s_upcall;
- axp->user = user;
-
- switch(axp->state){
- case DISCONNECTED:
- est_link(axp);
- lapbstate(axp,SETUP);
- break;
- case SETUP:
- free_q(&axp->txq);
- break;
- case DISCPENDING: /* Ignore */
- break;
- case RECOVERY:
- case CONNECTED:
- free_q(&axp->txq);
- est_link(axp);
- lapbstate(axp,SETUP);
- break;
- }
- return axp;
- }
-
- /* Send data on an AX.25 connection. Caller must provide PID */
- int
- send_ax25(axp,bp,pid)
- struct ax25_cb *axp;
- struct mbuf *bp;
- int pid;
- {
- struct mbuf *bp1;
-
- if(axp == NULLAX25 || bp == NULLBUF)
- return -1;
- while(len_mbuf(bp) > axp->paclen){
- dup_p(&bp1,bp,0,axp->paclen);
- pullup(&bp,NULLCHAR,axp->paclen);
- if(pid != -1){
- bp1 = pushdown(bp1,1);
- bp1->data[0] = pid;
- }
- enqueue(&axp->txq,bp1);
- }
- if(len_mbuf(bp) > 0){
- if(pid != -1){
- bp = pushdown(bp,1);
- bp->data[0] = pid;
- }
- enqueue(&axp->txq,bp);
- }
- return lapb_output(axp);
- }
-
- /* Receive incoming data on an AX.25 connection */
- struct mbuf *
- recv_ax25(axp,cnt)
- struct ax25_cb *axp;
- int16 cnt;
- {
- struct mbuf *bp;
-
- if(axp->rxq == NULLBUF)
- return NULLBUF;
-
- bp = axp->rxq;
- axp->rxq = NULLBUF;
-
- /* If this has un-busied us, send a RR to reopen the window */
- if(len_mbuf(bp) >= axp->window)
- sendctl(axp,RESPONSE,RR);
- return bp;
- }
-
- /* Close an AX.25 connection */
- int
- disc_ax25(axp)
- struct ax25_cb *axp;
- {
- if(axp == NULLAX25)
- return -1;
- switch(axp->state){
- case DISCONNECTED:
- break; /* Ignored */
- case DISCPENDING:
- lapbstate(axp,DISCONNECTED);
- break;
- case CONNECTED:
- case RECOVERY:
- free_q(&axp->txq);
- axp->retries = 0;
- sendctl(axp,COMMAND,DISC|PF);
- stop_timer(&axp->t3);
- start_timer(&axp->t1);
- lapbstate(axp,DISCPENDING);
- break;
- }
- return 0;
- }
-
- /* Verify that axp points to a valid ax25 control block */
- int
- ax25val(axp)
- struct ax25_cb *axp;
- {
- register struct ax25_cb *axp1;
- register int i;
-
- if(axp == NULLAX25)
- return 0; /* Null pointer can't be valid */
- for(i=0; i < NHASH; i++)
- for(axp1 = Ax25_cb[i];axp1 != NULLAX25; axp1 = axp1->next)
- if(axp1 == axp)
- return 1;
- return 0;
- }
-
- /* Force a retransmission */
- int
- kick_ax25(axp)
- struct ax25_cb *axp;
- {
- if(!ax25val(axp))
- return -1;
- recover((int *)axp);
- return 0;
- }
-
- /* Abruptly terminate an AX.25 connection */
- int
- reset_ax25(axp)
- struct ax25_cb *axp;
- {
- int user;
-
- if(axp == NULLAX25)
- return -1;
- user = axp->user;
- lapbstate(axp,DISCONNECTED);
- if(user == -1)
- del_ax25(axp);
- return 0;
- }
-